package top.kuanghua.upload.controller;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import top.kuanghua.upload.service.UploadService;

import java.io.IOException;

/**
 * @Title: UploadController @Description: @Auther:jzfai @Version: 1.0
 * @create 2020/3/4 21:58
 */
@RestController
@RequestMapping("upload")
@Api(tags="图片上传")
@DefaultProperties(defaultFallback = "fallBackMethod") // 指定一个类的全局熔断方法

public class UploadController {

    @Autowired
    private UploadService uploadService;

    @ApiOperation(value="上传图片", notes = "上传图片接口")
    @PostMapping("image")
    @HystrixCommand()
    public String uploadImage(@RequestParam("file") MultipartFile file)
            throws IOException, InterruptedException {
        String url = this.uploadService.upload(file);
//        Thread.sleep(5000);
        return url;
    }

    @PostMapping("FeignTest")
    @HystrixCommand()
    public String FeignTest(String name){
        System.out.println("好烦啊upload"+name);
        return name;
    }
    public String fallBackMethod(){
        return "请求繁忙，请稍后再试！";
    }
}
